//
//  ActivityViewController.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/14.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "ActivityViewController.h"
#import "NetWorkingHandle.h"
#import "ActivityModel.h"
#import "CellOfPic.h"
#import <WebKit/WebKit.h>
#import "ActivityModel.h"
#import "VcOfWebView.h"
#import "MJRefresh.h"
@interface ActivityViewController ()

@property (nonatomic, retain)NSMutableArray *mArrOfData;
@property (nonatomic, retain)NSMutableArray *mArr;
@property (nonatomic, retain)WKWebView *webView;
@property (nonatomic, retain)NSString *strOfc_id;
@end

@implementation ActivityViewController

- (void)dealloc{
    [_mArrOfData release];
    [_mArr release];
    [_webView release];
    
    [super dealloc];
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
    
    [self config];
    
    
    
    
    
}

- (void)config{
    
    [self.tableView registerClass:[CellOfPic class] forCellReuseIdentifier:@"pool"];
    
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self GetData];
        
        [self.tableView.mj_header endRefreshing];
    }];
    
    
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
       
        [self GetData];
        
        [self.tableView.mj_footer endRefreshing];
        
    }];
    
    [self.tableView.mj_header beginRefreshing];
    
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    
    
}


#if 1
#pragma mark - Data
- (void)GetData
{
    NSString *url = @"http://m.shougongke.com/index.php?&c=Course&a=activityList&vid=18";
    
    NetWorkingHandle *net = [[NetWorkingHandle alloc]init];
    self.mArr = [NSMutableArray array];
    [net netWorkingHandlerGetWithURL:url completion:^(id result, NSData *data, NSURLResponse *response, NSError *error)
    {
        
        if (result != nil)
        
        
        {
            //        NSLog(@"111%@", result);
            self.mArrOfData = result[@"data"];
            NSLog(@"222%@", self.mArrOfData);
            for (NSDictionary *dic in self.mArrOfData)
            {
                //            NSLog(@"aaaa%@", dic);
                ActivityModel *model = [[ActivityModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [self.mArr addObject:model];
                
            }
            
            
            
            [self.tableView reloadData];

        }

    }];
    
    [net release];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.mArrOfData.count;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 230;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CellOfPic *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    
//    NSLog(@"SHUZHU!!!!!%@", self.mArrOfData);
    cell.model = self.mArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
    
    
    
    
}
#pragma mark - 点击每行cell执行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ActivityModel *model = [self.mArr objectAtIndex:indexPath.row];
    self.strOfc_id = model.c_id;
    self.webView = [[WKWebView alloc]initWithFrame:self.view.frame];
    
    NSString *url = [NSString stringWithFormat:@"http://m.shougongke.com/index.php?c=Competition&cid=%@", self.strOfc_id];
    
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
   
    
    VcOfWebView *vc = [[VcOfWebView alloc]init];
   
    self.webView.frame = vc.view.frame;
    [vc.view addSubview:self.webView];
    
    [self.navigationController pushViewController:vc animated:YES];
    
    [vc release];
    [self.webView release];
    
    
    
}


#endif
@end
